package global

import (
	"database/sql"
	"time"
)

type SlowLogEntry struct {
	Time                                      string `json:"# Time:"`
	UserHost                                  string `json:"# User@Host:"`
	ProcessId                                 string `json:"Id:"`
	Schema                                    string `json:"# Schema:"`
	LastErrno                                 string `json:"Last_errno:"`
	Killed                                    string `json:"Killed:"`
	QueryTime                                 string `json:"# Query_time:"`
	LockTime                                  string `json:"Lock_time:"`
	RowsSent                                  string `json:"Rows_sent:"`
	RowsExamined                              string `json:"Rows_examined:"`
	RowsAffected                              string `json:"Rows_affected:"`
	BytesSent                                 string `json:"Bytes_sent:"`
	ProfileStart                              string `json:"# Profile_starting:"`
	ProfileExecutingHookOnTransactionBegin    string `json:"Profile_Executing_hook_on_transaction_begin.:"`
	ProfileExecutingHookOnTransactionBeginCpu string `json:"Profile_Executing_hook_on_transaction_begin._cpu:"`
	ProfileStarting                           string `json:"Profile_starting:"`
	ProfileStartingCpu                        string `json:"Profile_starting_cpu:"`
	ProfileCheckingPermissions                string `json:"Profile_checking_permissions:"`
	ProfileCheckingPermissionsCpu             string `json:"Profile_checking_permissions_cpu:"`
	ProfileOpeningTables                      string `json:"Profile_opening_tables:"`
	ProfileOpeningTablesCpu                   string `json:"Profile_opening_tables_cpu:"`
	ProfileInit                               string `json:"Profile_init:"`
	ProfileInitCpu                            string `json:"Profile_init_cpu:"`
	ProfileSystemLock                         string `json:"Profile_system_lock:"`
	ProfileSystemLockCpu                      string `json:"Profile_system_lock_cpu:"`
	ProfileOptimizing                         string `json:"Profile_optimizing:"`
	ProfileOptimizingCpu                      string `json:"Profile_optimizing_cpu:"`
	ProfileStatistics                         string `json:"Profile_statistics:"`
	ProfileStatisticsCpu                      string `json:"Profile_statistics_cpu:"`
	ProfilePreparing                          string `json:"Profile_preparing:"`
	ProfilePreparingCpu                       string `json:"Profile_preparing_cpu:"`
	ProfileExecuting                          string `json:"Profile_executing:"`
	ProfileExecutingCpu                       string `json:"Profile_executing_cpu:"`
	ProfileEnd                                string `json:"Profile_end:"`
	ProfileEndCpu                             string `json:"Profile_end_cpu:"`
	ProfileQueryEnd                           string `json:"Profile_query_end:"`
	ProfileQueryEndCpu                        string `json:"Profile_query_end_cpu:"`
	ProfileWaitingForHandlerCommit            string `json:"Profile_waiting_for_handler_commit:"`
	ProfileWaitingForHandlerCommitCpu         string `json:"Profile_waiting_for_handler_commit_cpu:"`
	ProfileClosingTables                      string `json:"Profile_closing_tables:"`
	ProfileClosingTablesCpu                   string `json:"Profile_closing_tables_cpu:"`
	ProfileFreeingItems                       string `json:"Profile_freeing_items:"`
	ProfileFreeingItemsCpu                    string `json:"Profile_freeing_items_cpu:"`
	ProfileLoggingSlowQuery                   string `json:"Profile_logging_slow_query:"`
	ProfileLoggingSlowQueryCpu                string `json:"Profile_logging_slow_query_cpu:"`
	ProfileTotal                              string `json:"# Profile_total:"`
	ProfileTotalCpu                           string `json:"Profile_total_cpu:"`
	UseSchema                                 string `json:"use"`
	TimeStamp                                 string `json:"SET timestamp"`
	Delimiter                                 string `json:";"`
	QuerySql                                  string `json:"querySql"`
	QueryType                                 string `json:"queryType"`
	HashSql                                   string
}

type HostSQL struct {
	User          string
	SqlId         string
	SqlText       string
	Executions    int
	ElaptimePerms string
	SqlType       string
	HashSql       string
	SqlGarth      []*SlowLogEntry
}
type PlayBackInput struct {
	LogSeq  int64
	SqlMode bool
	DB      map[string]*sql.DB
	TimeOut time.Duration
	SqlInfo *HostSQL
}
type PlayBack struct {
	ExecStatus string `json:"status"` //success、timeout、error
	ErrorCode  string `json:"errorCode"`
	ErrorInfo  string `json:"error"`
	TimeOut    int64  `json:"timeOut"`
}

// xls输出信息
type (
	XHotSqlSheetName struct {
		//XlsTerminal string `json:"db2s_terminal"`
		HotSQL   string `json:"热SQL 信息"`
		PlayBack string `json:"热SQL 回放"`
	}
	//terminal := strings.Join([]string{"user", "table", "checkMod", "Qps Sum", "select num", "insert num", "update num", "delete num", "status"}, global.StructColumnSplit)
	//oracleHotSQL := strings.Join([]string{"user", "sqlId", "executions", "elaptimePerms(ms)", "sql Type", "sql Text"}, global.StructColumnSplit)
	//hotSqlPlayBACKNormal := strings.Join([]string{"user", "sqlId", "executions", "elaptimePerms(ms)", "playBack executions", "playBack elaptimePerms(ms)", "exec status", "sql Type", "sql Text"}, global.StructColumnSplit)
	//hotSqlPlayBACKAbnormal := strings.Join([]string{"user", "sqlId", "executions", "elaptimePerms(ms)", "playBack executions", "playBack elaptimePerms(ms)", "exec status", "sql Type", "error code", "error info", "sql Text"}, global.StructColumnSplit)
	Thotsql struct {
		Seq          string `json:"seq"`
		Schema       string `json:"schema"`
		Table        string `json:"table"`
		CheckMode    string `json:"mode"`
		SourceNumber *int64 `json:"srcCount"`
		DestNumber   *int64 `json:"dstCount"`
		QpsSum       *int64 `json:"qps Sum"`
		SelectNum    *int64 `json:"select Num"`
		InsertNum    *int64 `json:"insert Num"`
		UpdateNum    *int64 `json:"update Num"`
		DeleteNum    *int64 `json:"delete Num"`
		Status       *int64 `json:"status"`
		CheckResult  string `json:"chkStat"`
	}
	XHotSqlSheetHead struct {
		User                string `json:"热SQL 用户"`
		SqlId               string `json:"热Sql ID"`
		HotSqlExecutions    int    `json:"热SQL 执行次数"`
		HotSqlElapTimePerms string `json:"热SQL 平均耗时"` //表的实际行数
		HotSqlQueryType     string `json:"热SQL 类型"`
		PlayBackExecutions  int64  `json:"回放SQL 执行次数"` //源端查询装填
		PlayBackExecTime    int64  `json:"回放SQL 执行耗时"` //目标端写入状态
		PlayBackExecStatus  string `json:"回放SQL 执行状态"` //同步状态   0为正常，-1为异常
		PlayBackErrorCode   string `json:"回放SQL 错误代码"`
		PlayBackErrorInfo   string `json:"回放SQL 错误信息"`
		PlayBackSql         string `json:"回放SQL 文本"`
		Comment             string `json:"备注"` //主要描述错误信息的记录
	}
)
